﻿function showhelp(area,button,label) { 
      var helparea = document.getElementById(area);
      var helpbutton = document.getElementById(button);
      if ( helparea.style.display == 'none' ) {
        helpbutton.value = 'Hide Help';
        helparea.style.display = 'block';
      } else {
        helparea.style.display = 'none';
        helpbutton.value = label;
      }
    }

var xmlhttp;

function updateHTML() {
	if ( xmlhttp.readyState == 4 && xmlhttp.status == 200 ) {
    var item = document.getElementById("resultarea");
    while ( item.hasChildNodes() ) {
      item.removeChild(item.firstChild);
    }
    item.innerHTML = xmlhttp.responseText;
  }
}

function requestHTML(url) {
  if (!xmlhttp) xmlhttp = new XMLHttpRequest();
  if (!xmlhttp) return;
  xmlhttp.open('GET', url, true);
  xmlhttp.onreadystatechange = updateHTML;
  xmlhttp.send(null);
}

function saveanalysis() {
   blazonText = document.getElementById('blazon').value;
   window.location.replace( '/include/shield/drawshield.php?asfile=1&blazon=' + encodeURIComponent(blazonText));
}

function analyseblazon() {
   blazonText = document.getElementById('blazon').value;
   f = document.getElementById('format');
   args = "&format=" + f.options[f.selectedIndex].value;
   if ( document.getElementById('complex').checked == true) args += "&complex=true";
   if ( document.getElementById('obsolete').checked == true) args += "&obsolete=true";
   if ( document.getElementById('tokens').checked == true) args += "&tokens=true";
	 // Add a random number to force resend (avoids caching)
   requestHTML('/include/drawshield3/analyse.php?' + args + '&rand=' + Math.random()
	   + '&blazon=' + encodeURIComponent(blazonText));
}
